<template>
  <div class="list-wrap">
    <div class="acc-item-list" v-for="(item, index) in agents" :key="index">
      <img
        style="width: 60px; height: 60px; border-radius: 50%"
        :src="item.logo"
      />
      <div style="flex: 1">
        <div class="name">{{ item.name }}</div>
        <div class="desc">
          {{ item.desc }}
        </div>
      </div>
      <div class="open-btn" @click="showApplyDialog(item)">申请开户</div>
    </div>
    <tcriteoApplyDialog
      v-model:value="tcriteoVisible"
      v-if="tcriteoVisible"
    ></tcriteoApplyDialog>
    <MediagoApplyDialog
      v-model:value="mediagoVisible"
      v-if="mediagoVisible"
    ></MediagoApplyDialog>
    <outbrainApplyDialog
      v-model:value="outbrainVisible"
      v-if="outbrainVisible"
    ></outbrainApplyDialog>
    <pinApplyDialog
      v-model:value="pinVisible"
      v-if="pinVisible"
    ></pinApplyDialog>
    <taboolaApplyDialog
      v-model:value="taboolaVisible"
      v-if="taboolaVisible"
    ></taboolaApplyDialog>
    <commonApplyDialog
      v-model:value="commonVisible"
      v-if="commonVisible"
      :systemType="systemType"
    ></commonApplyDialog>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { applyPlatform } from "@/const/index.ts";
import tcriteoApplyDialog from "./form/tcriteo-apply-dialog.vue";
import MediagoApplyDialog from "./form/mediago-apply-dialog.vue";
import outbrainApplyDialog from "./form/outbrain-apply-dialog.vue";
import pinApplyDialog from "./form/pin-apply-dialog.vue";
import taboolaApplyDialog from "./form/taboola-apply-dialog.vue";
import commonApplyDialog from "./form/common-apply-dialog.vue";

const tcriteoVisible = ref(false);
const mediagoVisible = ref(false);
const outbrainVisible = ref(false);
const taboolaVisible = ref(false);
const pinVisible = ref(false);
const commonVisible = ref(false);
const systemType = ref("");
const props = defineProps({
  agents: {
    type: Array,
    default: () => [],
  },
});

const showApplyDialog = (item) => {
  if (item.type === "Criteo") {
    tcriteoVisible.value = true;
  }
  if (item.type === "Mediago") {
    mediagoVisible.value = true;
  }
  if (item.type === "Outbrain") {
    outbrainVisible.value = true;
  }
  if (item.type === "Pin") {
    pinVisible.value = true;
  }
  if (item.type === "Taboola") {
    taboolaVisible.value = true;
  }
  if (item.type === "Linkedin") {
    commonVisible.value = true;
    systemType.value = applyPlatform.LINKEDIN;
  }
  if (item.type === "Yandex") {
    commonVisible.value = true;
    systemType.value = applyPlatform.YANDEX;
  }
  if (item.type === "Sanpchat") {
    commonVisible.value = true;
    systemType.value = applyPlatform.SANPCHAT;
  }
  if (item.type === "Twitter") {
    commonVisible.value = true;
    systemType.value = applyPlatform.TWITTER;
  }
};
</script>

<style lang="scss">
.list-wrap {
  margin: 0 20px 20px 20px;

  .acc-item-list {
    background-color: #f6f6f6;
    padding: 10px 20px;
    display: flex;
    margin-bottom: 10px;
    flex-direction: row;
    align-items: center;
    border-radius: 8px;

    .name {
      margin-left: 10px;
      color: #000;
      font-size: 14px;
      margin-bottom: 5px;
      font-weight: bold;
    }

    .desc {
      flex: 1;
      margin: 0 10px;
      font-size: 12px;
      color: #333;
    }

    .open-btn {
      background-color: #039691;
      width: 120px;
      align-items: center;
      display: flex;
      justify-content: center;
      cursor: pointer;
      color: #fff;
      font-size: 14px;
      height: 38px;
      border-radius: 30px;
    }
  }
}
</style>
